

#include <gtk/gtk.h>
#include <stdio.h>
#include "support.h"
#include "keypad.h"
#include "window.h" 
#include "statusbar.h"
#include "page_state.h"
#include "codeview.h"
#include "statusbar.h"
#include "fileops.h"

/*###################### Globals #######################*/
GtkWidget *dt_table,*al_table,*mc_table,*br_table;
GtkWidget *con_table,*hex_table;
GtkWidget *rega;
GtkWidget *regb;
GtkWidget *regc;
GtkWidget *regd;
GtkWidget *rege;
GtkWidget *regh;
GtkWidget *regl;
GtkWidget *regm;
GtkWidget *regsp;
GtkWidget *regpsw;


static int codeview_tab_disable;

/*############### inititilise the keypad state ##################*/
void gsim_init_keypad_state()
{
	gtk_widget_set_sensitive(dt_table ,TRUE );
	gtk_widget_set_sensitive(al_table ,TRUE );
	gtk_widget_set_sensitive(mc_table ,TRUE );
	gtk_widget_set_sensitive(br_table ,TRUE );
	gtk_widget_set_sensitive(con_table,FALSE );
	gtk_widget_set_sensitive(hex_table ,FALSE );
	gtk_widget_set_sensitive(rega ,FALSE );
	gtk_widget_set_sensitive(regb ,FALSE );
	gtk_widget_set_sensitive(regc ,FALSE );
	gtk_widget_set_sensitive(regd ,FALSE );
	gtk_widget_set_sensitive(rege ,FALSE );
	gtk_widget_set_sensitive(regh ,FALSE );
	gtk_widget_set_sensitive(regl ,FALSE );
	gtk_widget_set_sensitive(regm ,FALSE );
	gtk_widget_set_sensitive(regsp ,FALSE );
	gtk_widget_set_sensitive(regpsw ,FALSE );
}

/*############### Enable or disable Any key group ################*/
void gsim_keypad_set_state()
{
	if(codeview_tab_disable && edit_state)
		g_object_set(G_OBJECT(codeview_notebook),"show-tabs",FALSE,NULL);
	if(!instruction_enable)
	{
		gtk_tree_selection_set_mode(current_code_selection,GTK_SELECTION_SINGLE);
		if(if_have_iter())
			gtk_tree_selection_select_iter(current_code_selection,&current_code_iter);
		gsim_init_keypad_state();
		op_complete=1;
		if(edit_state)
		{
			codeview_tab_disable=0;
			g_object_set(G_OBJECT(codeview_notebook),"show-tabs",TRUE,NULL);
		}
		return;
	}
	
	op_complete=0;
	gtk_tree_selection_set_mode(current_code_selection,GTK_SELECTION_NONE);
	gtk_widget_set_sensitive(dt_table,!instruction_enable);
	gtk_widget_set_sensitive(al_table,!instruction_enable);
	gtk_widget_set_sensitive(mc_table,!instruction_enable);
	gtk_widget_set_sensitive(br_table,!instruction_enable);
	
	gtk_widget_set_sensitive(con_table,( condition_enable<=0));
	gtk_widget_set_sensitive(hex_table,( hexpad_enable<=0));
	gtk_widget_set_sensitive(rega,( a_enable<=0));
	gtk_widget_set_sensitive(regb,( b_enable<=0));
	gtk_widget_set_sensitive(regc,( c_enable<=0));
	gtk_widget_set_sensitive(regd,( d_enable<=0));
	gtk_widget_set_sensitive(rege,( e_enable<=0));
	gtk_widget_set_sensitive(regh,( h_enable<=0));
	gtk_widget_set_sensitive(regl,( l_enable<=0));
	gtk_widget_set_sensitive(regm,( m_enable<=0));
	gtk_widget_set_sensitive(regsp,( sp_enable<=0));
	gtk_widget_set_sensitive(regpsw,( psw_enable<=0));
	
	return;
}

/*############### scroll to the currently entered row #################*/
void scroll_to_row()
{
	GtkTreePath *path;
	path=gtk_tree_model_get_path(current_code_model,&current_code_iter);
	gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(current_code_tree),path,NULL,FALSE,0,0);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,TR_COL,code_tracker_pixmap,-1);
	
	/*update the marker position*/
	gchar *position;
	position=gtk_tree_path_to_string(path);
	sscanf(position,"%d",&row);
	//printf("updated_row->  %d\n",row);
}

/*############# Delete the marker of the on previus row ##############*/
void remove_marker(void)
{
	//printf("rm_row->  %d\n",row);
	if(row<0)
		return;
	gchar x[5];
	GtkTreeIter iter;
	sprintf(x,"%d",row);
	gtk_tree_model_get_iter_from_string(current_code_model,&iter,x);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&iter,TR_COL,NULL,-1);
}

/*############### Callbacks for various buttons of keypad ##################*/


void on_key0_clicked (GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"0",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key4_clicked (GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"4",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key8_clicked (GtkButton *button, gpointer  user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"8",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_keyc_clicked (GtkButton  *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"C",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key1_clicked(GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"1",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key5_clicked (GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"5",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key9_clicked(GtkButton*button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"9",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_keyd_clicked (GtkButton *button,gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"D",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key2_clicked(GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"2",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key6_clicked(GtkButton*button,gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"6",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_keya_clicked(GtkButton *button,gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"A",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_keye_clicked (GtkButton *button,gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"E",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key3_clicked(GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"3",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_key7_clicked(GtkButton *button,gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"7",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_keyb_clicked(GtkButton *button,gpointer  user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"B",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_keyf_clicked(GtkButton *button,gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"F",5);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1);
	instruction_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
	g_free(value);
}



void on_hexpad_clicked                      (GtkButton       *button,
                                        gpointer         user_data)
{

}



void on_rega_clicked (GtkButton *button, gpointer  user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"A",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regb_clicked (GtkButton *button, gpointer  user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"B",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regc_clicked (GtkButton *button, gpointer user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"C",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regd_clicked (GtkButton *button, gpointer  user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"D",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rege_clicked (GtkButton  *button, gpointer  user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"E",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regh_clicked (GtkButton *button, gpointer         user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"H",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regl_clicked   (GtkButton  *button, gpointer  user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"L",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regm_clicked(GtkButton  *button, gpointer         user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"M",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regsp_clicked(GtkButton *button,gpointer user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SP",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}


 void on_regpsw_clicked (GtkButton *button, gpointer user_data)
{
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"PSW",-1);
	column++;
	instruction_enable--;
	hexpad_enable--;
	condition_enable--;
	a_enable++;
	b_enable++;
	c_enable++;
	d_enable++;
	e_enable++;
	h_enable++;
	l_enable++;
	m_enable++;
	sp_enable++;
	psw_enable++;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_regpad_clicked                      (GtkButton       *button,
                                        gpointer         user_data)
{

}



void on_aci_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ACI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_adc_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   if(row>0)remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ADC",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_add_clicked(GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ADD",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_adi_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ADC",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ana_clicked(GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL; remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ANA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ani_clicked (GtkButton  *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ANI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_cma_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"CMA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_cmc_clicked  (GtkButton *button, gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"CMC",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_cmp_clicked  (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"CMP",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_cpi_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"CPI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_daa_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"DAA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_dad_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"DAD",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=0;
	l_enable=2;
	m_enable=2;
	sp_enable=0;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_dcr_clicked (GtkButton  *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"DCR",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_dcx_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"DCX",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=0;
	l_enable=2;
	m_enable=2;
	sp_enable=0;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_inr_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"INR",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_inx_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"INX",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=0;
	l_enable=2;
	m_enable=2;
	sp_enable=0;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ora_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ORA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ori_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"ORI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ral_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RAL",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rar_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RAR",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rlc_clicked(GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RLC",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rrc_clicked(GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RRC",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sbb_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SBB",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sbi_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SBI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_stc_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"STC",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sub_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SUB",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sui_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SUI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_xra_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"XRA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}


void on_xri_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"XRI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}


void on_airthmetic_clicked                  (GtkButton       *button,
                                        gpointer         user_data)
{

}


 void on_mov_clicked (GtkButton  *button, gpointer  user_data)
{	
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"MOV",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=3;
	condition_enable=3;
	a_enable=-1;
	b_enable=-1;
	c_enable=-1;
	d_enable=-1;
	e_enable=-1;
	h_enable=-1;
	l_enable=-1;
	m_enable=-1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_shld_clicked(GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SHLD",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=4;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_mvi_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"MVI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=3;
	hexpad_enable=1;
	condition_enable=4;
	a_enable=0;
	b_enable=0;
	c_enable=0;
	d_enable=0;
	e_enable=0;
	h_enable=0;
	l_enable=0;
	m_enable=0;
	sp_enable=4;
	psw_enable=4;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_pchl_clicked(GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"PCHL",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_xchg_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"XCHG",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ldax_clicked (GtkButton *button, gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"LDAX",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=2;
	l_enable=2;
	m_enable=2;
	sp_enable=3;
	psw_enable=3;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_pop_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"POP",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=0;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=0;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_push_clicked (GtkButton  *button, gpointer   user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"PUSH",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=0;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=0;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_xthl_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"XTHL",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sta_clicked (GtkButton *button, gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"STA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=4;
	hexpad_enable=0;
	condition_enable=3;
	a_enable=3;
	b_enable=3;
	c_enable=3;
	d_enable=3;
	e_enable=3;
	h_enable=3;
	l_enable=3;
	m_enable=3;
	sp_enable=3;
	psw_enable=3;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_lda_clicked (GtkButton *button,gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"LDA",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=4;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sphl_clicked (GtkButton  *button, gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SPHL",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_lhld_clicked(GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"LHLD",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=4;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_lxi_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"LXI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=5;
	hexpad_enable=1;
	condition_enable=4;
	a_enable=4;
	b_enable=0;
	c_enable=4;
	d_enable=0;
	e_enable=4;
	h_enable=0;
	l_enable=4;
	m_enable=4;
	sp_enable=0;
	psw_enable=4;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_stax_clicked (GtkButton *button, gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"STAX",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=2;
	a_enable=2;
	b_enable=0;
	c_enable=2;
	d_enable=0;
	e_enable=2;
	h_enable=2;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_in_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"IN",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_out_clicked (GtkButton *button, gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"OUT",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=2;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_data_transfer_clicked               (GtkButton       *button,
                                        gpointer         user_data)
{

}



void on_jmp_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"JMP",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=4;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_call_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"CALL",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=4;
	hexpad_enable=0;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ret_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RET",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_jx_clicked (GtkButton  *button,gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"J",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	instruction_enable=5;
	hexpad_enable=1;
	condition_enable=0;
	a_enable=2;
	b_enable=2;
	c_enable=2;
	d_enable=2;
	e_enable=2;
	h_enable=2;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_cx_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"C",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	instruction_enable=5;
	hexpad_enable=1;
	condition_enable=0;
	a_enable=2;
	b_enable=2;
	c_enable=2;
	d_enable=2;
	e_enable=2;
	h_enable=2;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rx_clicked (GtkButton *button,gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"R",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	instruction_enable=1;
	hexpad_enable=2;
	condition_enable=0;
	a_enable=2;
	b_enable=2;
	c_enable=2;
	d_enable=2;
	e_enable=2;
	h_enable=2;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_branch_clicked                      (GtkButton       *button,
                                        gpointer         user_data)
{

}



void on_carry_clicked(GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"C",3);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_zero_clicked (GtkButton  *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"Z",3);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_evan_piraty_clicked (GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"PE",4);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_plus_clicked (GtkButton *button, gpointer  user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"P",3);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_nocarry_clicked  (GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"NC",4);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_nozero_clicked (GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"NZ",4);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_odd_piraty_clicked (GtkButton  *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"PO",4);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_minus_clicked(GtkButton *button, gpointer user_data)
{
	gchar *value;
	value=g_malloc(5);     
	gtk_tree_model_get(current_code_model,&current_code_iter,column,&value,-1);
	g_strlcat(value,"M",3);
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,value,-1); 
	g_free(value);
	column++; 
	instruction_enable--;
	hexpad_enable--;
	condition_enable++;
	a_enable--;
	b_enable--;
	c_enable--;
	d_enable--;
	e_enable--;
	h_enable--;
	l_enable--;
	m_enable--;
	sp_enable--;
	psw_enable--;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_condition_clicked (GtkButton *button, gpointer user_data)
{

}



void on_hlt_clicked (GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"HLT",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_nop_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"NOP",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_di_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"DI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_ei_clicked(GtkButton *button,gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"EI",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rim_clicked (GtkButton *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RIM",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_sim_clicked (GtkButton *button,  gpointer  user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"SIM",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=0;
	hexpad_enable=1;
	condition_enable=1;
	a_enable=1;
	b_enable=1;
	c_enable=1;
	d_enable=1;
	e_enable=1;
	h_enable=1;
	l_enable=1;
	m_enable=1;
	sp_enable=1;
	psw_enable=1;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_rst_clicked(GtkButton  *button, gpointer user_data)
{
	if(current_code_model==NULL)
		return;
	column=MNE_COL;   remove_marker();
	if (edit_state)
	{
		if(gtk_tree_selection_get_selected(current_code_selection,&current_code_model, &current_code_iter)==FALSE)
			return; else codeview_tab_disable=1;
	}
	else
		gtk_tree_store_append(GTK_TREE_STORE(current_code_model), &current_code_iter,NULL);
	scroll_to_row();
	gtk_tree_store_set(GTK_TREE_STORE(current_code_model),&current_code_iter,column,"RST",ADDR_COL,"",LABEL_COL,"",OP1_COL,"",OP2_COL,"",COMMT_COL,"",-1);
	column++; 
	instruction_enable=1;
	hexpad_enable=0;
	condition_enable=2;
	a_enable=2;
	b_enable=2;
	c_enable=2;
	d_enable=2;
	e_enable=2;
	h_enable=2;
	l_enable=2;
	m_enable=2;
	sp_enable=2;
	psw_enable=2;
	save_state=1;
	gsim_keypad_set_state();
	gsim_update_statusbar(FILE_SBAR,filename);
}



void on_machine_control_clicked (GtkButton *button, gpointer  user_data)
{

}

/*###################### Show / hide Keypad ######################*/
gboolean show_hide_keypad(void)
{
	if(state_keypad)
	{
		state_keypad=0;
		gtk_widget_hide_all(gsim_keypad);
		gsim_update_statusbar(DESC_SBAR,_("Keypad off"));
	}
	else
	{
		state_keypad=1;
		gtk_widget_show_all(gsim_keypad);
		gsim_update_statusbar(DESC_SBAR,_("Keypad on"));
	}
	return TRUE;
}

/*###################### Create the keypad #######################*/
/*############## This source is generated by Glade ###############*/
GtkWidget *gsim_create_keypad (void)
{
  GtkWidget *keypad;
  GtkWidget *table1;
  GtkWidget *table4;
  GtkWidget *key0;
  GtkWidget *key4;
  GtkWidget *key8;
  GtkWidget *keyc;
  GtkWidget *key1;
  GtkWidget *key5;
  GtkWidget *key9;
  GtkWidget *keyd;
  GtkWidget *key2;
  GtkWidget *key6;
  GtkWidget *keya;
  GtkWidget *keye;
  GtkWidget *key3;
  GtkWidget *key7;
  GtkWidget *keyb;
  GtkWidget *keyf;
  GtkWidget *hexpad;
  GtkWidget *table5;
  GtkWidget *regpad;
  GtkWidget *table3;
  GtkWidget *aci;
  GtkWidget *adc;
  GtkWidget *add;
  GtkWidget *adi;
  GtkWidget *ana;
  GtkWidget *ani;
  GtkWidget *cma;
  GtkWidget *cmc;
  GtkWidget *cmp;
  GtkWidget *cpi;
  GtkWidget *daa;
  GtkWidget *dad;
  GtkWidget *dcr;
  GtkWidget *dcx;
  GtkWidget *inr;
  GtkWidget *inx;
  GtkWidget *ora;
  GtkWidget *ori;
  GtkWidget *ral;
  GtkWidget *rar;
  GtkWidget *rlc;
  GtkWidget *rrc;
  GtkWidget *sbb;
  GtkWidget *sbi;
  GtkWidget *stc;
  GtkWidget *sub;
  GtkWidget *sui;
  GtkWidget *xra;
  GtkWidget *xri;
  GtkWidget *airthmetic;
  GtkWidget *data_transfer_table;
  GtkWidget *mov;
  GtkWidget *shld;
  GtkWidget *mvi;
  GtkWidget *pchl;
  GtkWidget *xchg;
  GtkWidget *ldax;
  GtkWidget *pop;
  GtkWidget *push;
  GtkWidget *xthl;
  GtkWidget *sta;
  GtkWidget *lda;
  GtkWidget *sphl;
  GtkWidget *lhld;
  GtkWidget *lxi;
  GtkWidget *stax;
  GtkWidget *in;
  GtkWidget *out;
  GtkWidget *data_transfer;
  GtkWidget *table6;
  GtkWidget *jmp;
  GtkWidget *call;
  GtkWidget *ret;
  GtkWidget *jx;
  GtkWidget *cx;
  GtkWidget *rx;
  GtkWidget *branch;
  GtkWidget *table7;
  GtkWidget *carry;
  GtkWidget *zero;
  GtkWidget *evan_piraty;
  GtkWidget *plus;
  GtkWidget *nocarry;
  GtkWidget *nozero;
  GtkWidget *odd_piraty;
  GtkWidget *minus;
  GtkWidget *condition;
  GtkWidget *table8;
  GtkWidget *hlt; 
  GtkWidget *nop;
  GtkWidget *di;
  GtkWidget *ei;
  GtkWidget *rim;
  GtkWidget *sim;
  GtkWidget *rst;
  GtkWidget *machine_control;
  
  
  keypad = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (keypad), _("Keypad"));
  gtk_window_set_resizable (GTK_WINDOW (keypad), FALSE);
  g_signal_connect(G_OBJECT(keypad),"delete-event",
						G_CALLBACK(show_hide_keypad),NULL);

  table1 = gtk_table_new (5, 2, FALSE);
  gtk_widget_show (table1);
  gtk_container_add (GTK_CONTAINER (keypad), table1);

  table4 = gtk_table_new (5, 4, FALSE);
  gtk_widget_show (table4);
  gtk_table_attach (GTK_TABLE (table1), table4, 0, 1, 2, 3,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  key0 = gtk_button_new_with_mnemonic (" 0  ");
  gtk_widget_show (key0);
  gtk_table_attach (GTK_TABLE (table4), key0, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key4 = gtk_button_new_with_mnemonic (" 4  ");
  gtk_widget_show (key4);
  gtk_table_attach (GTK_TABLE (table4), key4, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key8 = gtk_button_new_with_mnemonic ("8 ");
  gtk_widget_show (key8);
  gtk_table_attach (GTK_TABLE (table4), key8, 0, 1, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  keyc = gtk_button_new_with_mnemonic ("C ");
  gtk_widget_show (keyc);
  gtk_table_attach (GTK_TABLE (table4), keyc, 0, 1, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key1 = gtk_button_new_with_mnemonic ("  1  ");
  gtk_widget_show (key1);
  gtk_table_attach (GTK_TABLE (table4), key1, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key5 = gtk_button_new_with_mnemonic ("5");
  gtk_widget_show (key5);
  gtk_table_attach (GTK_TABLE (table4), key5, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key9 = gtk_button_new_with_mnemonic ("9");
  gtk_widget_show (key9);
  gtk_table_attach (GTK_TABLE (table4), key9, 1, 2, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  keyd = gtk_button_new_with_mnemonic ("D");
  gtk_widget_show (keyd);
  gtk_table_attach (GTK_TABLE (table4), keyd, 1, 2, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key2 = gtk_button_new_with_mnemonic ("  2  ");
  gtk_widget_show (key2);
  gtk_table_attach (GTK_TABLE (table4), key2, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key6 = gtk_button_new_with_mnemonic ("6");
  gtk_widget_show (key6);
  gtk_table_attach (GTK_TABLE (table4), key6, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  keya = gtk_button_new_with_mnemonic ("A");
  gtk_widget_show (keya);
  gtk_table_attach (GTK_TABLE (table4), keya, 2, 3, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  keye = gtk_button_new_with_mnemonic ("E");
  gtk_widget_show (keye);
  gtk_table_attach (GTK_TABLE (table4), keye, 2, 3, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key3 = gtk_button_new_with_mnemonic ("  3 ");
  gtk_widget_show (key3);
  gtk_table_attach (GTK_TABLE (table4), key3, 3, 4, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  key7 = gtk_button_new_with_mnemonic ("7");
  gtk_widget_show (key7);
  gtk_table_attach (GTK_TABLE (table4), key7, 3, 4, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  keyb = gtk_button_new_with_mnemonic ("B");
  gtk_widget_show (keyb);
  gtk_table_attach (GTK_TABLE (table4), keyb, 3, 4, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  keyf = gtk_button_new_with_mnemonic ("F");
  gtk_widget_show (keyf);
  gtk_table_attach (GTK_TABLE (table4), keyf, 3, 4, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  hexpad = gtk_button_new_with_mnemonic ("HEX KEYPAD");
  gtk_widget_show (hexpad);
  gtk_table_attach (GTK_TABLE (table4), hexpad, 0, 4, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  table5 = gtk_table_new (5, 3, FALSE);
  gtk_widget_show (table5);
  gtk_table_attach (GTK_TABLE (table1), table5, 1, 2, 2, 3,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  rega = gtk_button_new_with_mnemonic ("  A   ");
  gtk_widget_show (rega);
  gtk_table_attach (GTK_TABLE (table5), rega, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regb = gtk_button_new_with_mnemonic ("B");
  gtk_widget_show (regb);
  gtk_table_attach (GTK_TABLE (table5), regb, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regc = gtk_button_new_with_mnemonic ("  C   ");
  gtk_widget_show (regc);
  gtk_table_attach (GTK_TABLE (table5), regc, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regd = gtk_button_new_with_mnemonic ("D");
  gtk_widget_show (regd);
  gtk_table_attach (GTK_TABLE (table5), regd, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rege = gtk_button_new_with_mnemonic ("E");
  gtk_widget_show (rege);
  gtk_table_attach (GTK_TABLE (table5), rege, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regh = gtk_button_new_with_mnemonic ("H");
  gtk_widget_show (regh);
  gtk_table_attach (GTK_TABLE (table5), regh, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regl = gtk_button_new_with_mnemonic ("L");
  gtk_widget_show (regl);
  gtk_table_attach (GTK_TABLE (table5), regl, 0, 1, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regm = gtk_button_new_with_mnemonic ("M");
  gtk_widget_show (regm);
  gtk_table_attach (GTK_TABLE (table5), regm, 1, 2, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regsp = gtk_button_new_with_mnemonic ("SP");
  gtk_widget_show (regsp);
  gtk_table_attach (GTK_TABLE (table5), regsp, 2, 3, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regpsw = gtk_button_new_with_mnemonic ("PSW");
  gtk_widget_show (regpsw);
  gtk_table_attach (GTK_TABLE (table5), regpsw, 1, 2, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  regpad = gtk_button_new_with_mnemonic ("REG KEYPAD");
  gtk_widget_show (regpad);
  gtk_table_attach (GTK_TABLE (table5), regpad, 0, 3, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  table3 = gtk_table_new (5, 7, FALSE);
  gtk_widget_show (table3);
  gtk_table_attach (GTK_TABLE (table1), table3, 0, 2, 1, 2,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  aci = gtk_button_new_with_mnemonic ("ACI");
  gtk_widget_show (aci);
  gtk_table_attach (GTK_TABLE (table3), aci, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  adc = gtk_button_new_with_mnemonic ("ADC");
  gtk_widget_show (adc);
  gtk_table_attach (GTK_TABLE (table3), adc, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  add = gtk_button_new_with_mnemonic ("ADD");
  gtk_widget_show (add);
  gtk_table_attach (GTK_TABLE (table3), add, 0, 1, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  adi = gtk_button_new_with_mnemonic ("ADI");
  gtk_widget_show (adi);
  gtk_table_attach (GTK_TABLE (table3), adi, 0, 1, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ana = gtk_button_new_with_mnemonic ("ANA");
  gtk_widget_show (ana);
  gtk_table_attach (GTK_TABLE (table3), ana, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ani = gtk_button_new_with_mnemonic ("ANI");
  gtk_widget_show (ani);
  gtk_table_attach (GTK_TABLE (table3), ani, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  cma = gtk_button_new_with_mnemonic ("CMA");
  gtk_widget_show (cma);
  gtk_table_attach (GTK_TABLE (table3), cma, 1, 2, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  cmc = gtk_button_new_with_mnemonic ("CMC");
  gtk_widget_show (cmc);
  gtk_table_attach (GTK_TABLE (table3), cmc, 1, 2, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  cmp = gtk_button_new_with_mnemonic ("CMP");
  gtk_widget_show (cmp);
  gtk_table_attach (GTK_TABLE (table3), cmp, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  cpi = gtk_button_new_with_mnemonic ("CPI");
  gtk_widget_show (cpi);
  gtk_table_attach (GTK_TABLE (table3), cpi, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  daa = gtk_button_new_with_mnemonic ("DAA");
  gtk_widget_show (daa);
  gtk_table_attach (GTK_TABLE (table3), daa, 2, 3, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  dad = gtk_button_new_with_mnemonic ("DAD");
  gtk_widget_show (dad);
  gtk_table_attach (GTK_TABLE (table3), dad, 2, 3, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  dcr = gtk_button_new_with_mnemonic ("DCR");
  gtk_widget_show (dcr);
  gtk_table_attach (GTK_TABLE (table3), dcr, 3, 4, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  dcx = gtk_button_new_with_mnemonic ("DCX");
  gtk_widget_show (dcx);
  gtk_table_attach (GTK_TABLE (table3), dcx, 3, 4, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  inr = gtk_button_new_with_mnemonic ("INR");
  gtk_widget_show (inr);
  gtk_table_attach (GTK_TABLE (table3), inr, 3, 4, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  inx = gtk_button_new_with_mnemonic ("INX");
  gtk_widget_show (inx);
  gtk_table_attach (GTK_TABLE (table3), inx, 3, 4, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ora = gtk_button_new_with_mnemonic ("ORA");
  gtk_widget_show (ora);
  gtk_table_attach (GTK_TABLE (table3), ora, 4, 5, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ori = gtk_button_new_with_mnemonic ("ORI");
  gtk_widget_show (ori);
  gtk_table_attach (GTK_TABLE (table3), ori, 4, 5, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ral = gtk_button_new_with_mnemonic ("RAL");
  gtk_widget_show (ral);
  gtk_table_attach (GTK_TABLE (table3), ral, 4, 5, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rar = gtk_button_new_with_mnemonic ("RAR");
  gtk_widget_show (rar);
  gtk_table_attach (GTK_TABLE (table3), rar, 4, 5, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rlc = gtk_button_new_with_mnemonic ("RLC");
  gtk_widget_show (rlc);
  gtk_table_attach (GTK_TABLE (table3), rlc, 5, 6, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rrc = gtk_button_new_with_mnemonic ("RRC");
  gtk_widget_show (rrc);
  gtk_table_attach (GTK_TABLE (table3), rrc, 5, 6, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sbb = gtk_button_new_with_mnemonic ("SBB");
  gtk_widget_show (sbb);
  gtk_table_attach (GTK_TABLE (table3), sbb, 5, 6, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sbi = gtk_button_new_with_mnemonic ("SBI");
  gtk_widget_show (sbi);
  gtk_table_attach (GTK_TABLE (table3), sbi, 5, 6, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  stc = gtk_button_new_with_mnemonic ("STC");
  gtk_widget_show (stc);
  gtk_table_attach (GTK_TABLE (table3), stc, 6, 7, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sub = gtk_button_new_with_mnemonic ("SUB");
  gtk_widget_show (sub);
  gtk_table_attach (GTK_TABLE (table3), sub, 6, 7, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sui = gtk_button_new_with_mnemonic ("SUI");
  gtk_widget_show (sui);
  gtk_table_attach (GTK_TABLE (table3), sui, 6, 7, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  xra = gtk_button_new_with_mnemonic ("XRA");
  gtk_widget_show (xra);
  gtk_table_attach (GTK_TABLE (table3), xra, 6, 7, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  xri = gtk_button_new_with_mnemonic ("XRI");
  gtk_widget_show (xri);
  gtk_table_attach (GTK_TABLE (table3), xri, 6, 7, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  airthmetic = gtk_button_new_with_mnemonic ("AIRTHMETIC / LOGICAL");
  gtk_widget_show (airthmetic);
  gtk_table_attach (GTK_TABLE (table3), airthmetic, 0, 6, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  data_transfer_table = gtk_table_new (3, 7, FALSE);
  gtk_widget_show (data_transfer_table);
  gtk_table_attach (GTK_TABLE (table1), data_transfer_table, 0, 2, 0, 1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  mov = gtk_button_new_with_mnemonic ("MOV");
  gtk_widget_show (mov);
  gtk_table_attach (GTK_TABLE (data_transfer_table), mov, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  shld = gtk_button_new_with_mnemonic ("SHLD");
  gtk_widget_show (shld);
  gtk_table_attach (GTK_TABLE (data_transfer_table), shld, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  mvi = gtk_button_new_with_mnemonic ("MVI");
  gtk_widget_show (mvi);
  gtk_table_attach (GTK_TABLE (data_transfer_table), mvi, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  pchl = gtk_button_new_with_mnemonic ("PCHL");
  gtk_widget_show (pchl);
  gtk_table_attach (GTK_TABLE (data_transfer_table), pchl, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  xchg = gtk_button_new_with_mnemonic ("XCHG");
  gtk_widget_show (xchg);
  gtk_table_attach (GTK_TABLE (data_transfer_table), xchg, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ldax = gtk_button_new_with_mnemonic ("LDAX");
  gtk_widget_show (ldax);
  gtk_table_attach (GTK_TABLE (data_transfer_table), ldax, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  pop = gtk_button_new_with_mnemonic ("POP");
  gtk_widget_show (pop);
  gtk_table_attach (GTK_TABLE (data_transfer_table), pop, 3, 4, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  push = gtk_button_new_with_mnemonic ("PUSH");
  gtk_widget_show (push);
  gtk_table_attach (GTK_TABLE (data_transfer_table), push, 3, 4, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  xthl = gtk_button_new_with_mnemonic ("XTHL");
  gtk_widget_show (xthl);
  gtk_table_attach (GTK_TABLE (data_transfer_table), xthl, 4, 5, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sta = gtk_button_new_with_mnemonic ("STA");
  gtk_widget_show (sta);
  gtk_table_attach (GTK_TABLE (data_transfer_table), sta, 4, 5, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  lda = gtk_button_new_with_mnemonic ("LDA");
  gtk_widget_show (lda);
  gtk_table_attach (GTK_TABLE (data_transfer_table), lda, 4, 5, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sphl = gtk_button_new_with_mnemonic ("SPHL");
  gtk_widget_show (sphl);
  gtk_table_attach (GTK_TABLE (data_transfer_table), sphl, 5, 6, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  lhld = gtk_button_new_with_mnemonic ("LHLD");
  gtk_widget_show (lhld);
  gtk_table_attach (GTK_TABLE (data_transfer_table), lhld, 5, 6, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  lxi = gtk_button_new_with_mnemonic ("LXI");
  gtk_widget_show (lxi);
  gtk_table_attach (GTK_TABLE (data_transfer_table), lxi, 5, 6, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  stax = gtk_button_new_with_mnemonic ("STAX");
  gtk_widget_show (stax);
  gtk_table_attach (GTK_TABLE (data_transfer_table), stax, 6, 7, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  in = gtk_button_new_with_mnemonic ("IN");
  gtk_widget_show (in);
  gtk_table_attach (GTK_TABLE (data_transfer_table), in, 6, 7, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  out = gtk_button_new_with_mnemonic ("OUT");
  gtk_widget_show (out);
  gtk_table_attach (GTK_TABLE (data_transfer_table), out, 6, 7, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  data_transfer = gtk_button_new_with_mnemonic ("DATA TRANSFER");
  gtk_widget_show (data_transfer);
  gtk_table_attach (GTK_TABLE (data_transfer_table), data_transfer, 0, 4, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  table6 = gtk_table_new (3, 3, FALSE);
  gtk_widget_show (table6);
  gtk_table_attach (GTK_TABLE (table1), table6, 0, 1, 3, 4,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  jmp = gtk_button_new_with_mnemonic ("JMP ");
  gtk_widget_show (jmp);
  gtk_table_attach (GTK_TABLE (table6), jmp, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  call = gtk_button_new_with_mnemonic ("CALL");
  gtk_widget_show (call);
  gtk_table_attach (GTK_TABLE (table6), call, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ret = gtk_button_new_with_mnemonic (" RET");
  gtk_widget_show (ret);
  gtk_table_attach (GTK_TABLE (table6), ret, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  jx = gtk_button_new_with_mnemonic ("Jx");
  gtk_widget_show (jx);
  gtk_table_attach (GTK_TABLE (table6), jx, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  cx = gtk_button_new_with_mnemonic ("Cx");
  gtk_widget_show (cx);
  gtk_table_attach (GTK_TABLE (table6), cx, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rx = gtk_button_new_with_mnemonic ("Rx");
  gtk_widget_show (rx);
  gtk_table_attach (GTK_TABLE (table6), rx, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  branch = gtk_button_new_with_mnemonic ("BRANCH");
  gtk_widget_show (branch);
  gtk_table_attach (GTK_TABLE (table6), branch, 0, 3, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  table7 = gtk_table_new (3, 4, FALSE);
  gtk_widget_show (table7);
  gtk_table_attach (GTK_TABLE (table1), table7, 1, 2, 3, 4,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  carry = gtk_button_new_with_mnemonic ("C");
  gtk_widget_show (carry);
  gtk_table_attach (GTK_TABLE (table7), carry, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  zero = gtk_button_new_with_mnemonic ("Z");
  gtk_widget_show (zero);
  gtk_table_attach (GTK_TABLE (table7), zero, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  evan_piraty = gtk_button_new_with_mnemonic ("PE");
  gtk_widget_show (evan_piraty);
  gtk_table_attach (GTK_TABLE (table7), evan_piraty, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  plus = gtk_button_new_with_mnemonic (" P  ");
  gtk_widget_show (plus);
  gtk_table_attach (GTK_TABLE (table7), plus, 3, 4, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  nocarry = gtk_button_new_with_mnemonic ("NC");
  gtk_widget_show (nocarry);
  gtk_table_attach (GTK_TABLE (table7), nocarry, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  nozero = gtk_button_new_with_mnemonic ("NZ");
  gtk_widget_show (nozero);
  gtk_table_attach (GTK_TABLE (table7), nozero, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  odd_piraty = gtk_button_new_with_mnemonic ("PO");
  gtk_widget_show (odd_piraty);
  gtk_table_attach (GTK_TABLE (table7), odd_piraty, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  minus = gtk_button_new_with_mnemonic ("M");
  gtk_widget_show (minus);
  gtk_table_attach (GTK_TABLE (table7), minus, 3, 4, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  condition = gtk_button_new_with_mnemonic ("CONDITION");
  gtk_widget_show (condition);
  gtk_table_attach (GTK_TABLE (table7), condition, 0, 4, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  table8 = gtk_table_new (2, 7, FALSE);
  gtk_widget_show (table8);
  gtk_table_attach (GTK_TABLE (table1), table8, 0, 2, 4, 5,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 4, 4);

  hlt = gtk_button_new_with_mnemonic ("HLT");
  gtk_widget_show (hlt);
  gtk_table_attach (GTK_TABLE (table8), hlt, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  nop = gtk_button_new_with_mnemonic ("NOP");
  gtk_widget_show (nop);
  gtk_table_attach (GTK_TABLE (table8), nop, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  di = gtk_button_new_with_mnemonic ("  DI  ");
  gtk_widget_show (di);
  gtk_table_attach (GTK_TABLE (table8), di, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  ei = gtk_button_new_with_mnemonic ("  EI  ");
  gtk_widget_show (ei);
  gtk_table_attach (GTK_TABLE (table8), ei, 3, 4, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rim = gtk_button_new_with_mnemonic ("RIM");
  gtk_widget_show (rim);
  gtk_table_attach (GTK_TABLE (table8), rim, 4, 5, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  sim = gtk_button_new_with_mnemonic ("SIM");
  gtk_widget_show (sim);
  gtk_table_attach (GTK_TABLE (table8), sim, 5, 6, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  rst = gtk_button_new_with_mnemonic ("RST");
  gtk_widget_show (rst);
  gtk_table_attach (GTK_TABLE (table8), rst, 6, 7, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  machine_control = gtk_button_new_with_mnemonic ("MACHINE CONTROL");
  gtk_widget_show (machine_control);
  gtk_table_attach (GTK_TABLE (table8), machine_control, 0, 7, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  g_signal_connect ((gpointer) key0, "clicked",
                    G_CALLBACK (on_key0_clicked),
                    NULL);
  g_signal_connect ((gpointer) key4, "clicked",
                    G_CALLBACK (on_key4_clicked),
                    NULL);
  g_signal_connect ((gpointer) key8, "clicked",
                    G_CALLBACK (on_key8_clicked),
                    NULL);
  g_signal_connect ((gpointer) keyc, "clicked",
                    G_CALLBACK (on_keyc_clicked),
                    NULL);
  g_signal_connect ((gpointer) key1, "clicked",
                    G_CALLBACK (on_key1_clicked),
                    NULL);
  g_signal_connect ((gpointer) key5, "clicked",
                    G_CALLBACK (on_key5_clicked),
                    NULL);
  g_signal_connect ((gpointer) key9, "clicked",
                    G_CALLBACK (on_key9_clicked),
                    NULL);
  g_signal_connect ((gpointer) keyd, "clicked",
                    G_CALLBACK (on_keyd_clicked),
                    NULL);
  g_signal_connect ((gpointer) key2, "clicked",
                    G_CALLBACK (on_key2_clicked),
                    NULL);
  g_signal_connect ((gpointer) key6, "clicked",
                    G_CALLBACK (on_key6_clicked),
                    NULL);
  g_signal_connect ((gpointer) keya, "clicked",
                    G_CALLBACK (on_keya_clicked),
                    NULL);
  g_signal_connect ((gpointer) keye, "clicked",
                    G_CALLBACK (on_keye_clicked),
                    NULL);
  g_signal_connect ((gpointer) key3, "clicked",
                    G_CALLBACK (on_key3_clicked),
                    NULL);
  g_signal_connect ((gpointer) key7, "clicked",
                    G_CALLBACK (on_key7_clicked),
                    NULL);
  g_signal_connect ((gpointer) keyb, "clicked",
                    G_CALLBACK (on_keyb_clicked),
                    NULL);
  g_signal_connect ((gpointer) keyf, "clicked",
                    G_CALLBACK (on_keyf_clicked),
                    NULL);
  g_signal_connect ((gpointer) hexpad, "clicked",
                    G_CALLBACK (on_hexpad_clicked),
                    NULL);
  g_signal_connect ((gpointer) rega, "clicked",
                    G_CALLBACK (on_rega_clicked),
                    NULL);
  g_signal_connect ((gpointer) regb, "clicked",
                    G_CALLBACK (on_regb_clicked),
                    NULL);
  g_signal_connect ((gpointer) regc, "clicked",
                    G_CALLBACK (on_regc_clicked),
                    NULL);
  g_signal_connect ((gpointer) regd, "clicked",
                    G_CALLBACK (on_regd_clicked),
                    NULL);
  g_signal_connect ((gpointer) rege, "clicked",
                    G_CALLBACK (on_rege_clicked),
                    NULL);
  g_signal_connect ((gpointer) regh, "clicked",
                    G_CALLBACK (on_regh_clicked),
                    NULL);
  g_signal_connect ((gpointer) regl, "clicked",
                    G_CALLBACK (on_regl_clicked),
                    NULL);
  g_signal_connect ((gpointer) regm, "clicked",
                    G_CALLBACK (on_regm_clicked),
                    NULL);
  g_signal_connect ((gpointer) regsp, "clicked",
                    G_CALLBACK (on_regsp_clicked),
                    NULL);
  g_signal_connect ((gpointer) regpsw, "clicked",
                    G_CALLBACK (on_regpsw_clicked),
                    NULL);
  g_signal_connect ((gpointer) regpad, "clicked",
                    G_CALLBACK (on_regpad_clicked),
                    NULL);
  g_signal_connect ((gpointer) aci, "clicked",
                    G_CALLBACK (on_aci_clicked),
                    NULL);
  g_signal_connect ((gpointer) adc, "clicked",
                    G_CALLBACK (on_adc_clicked),
                    NULL);
  g_signal_connect ((gpointer) add, "clicked",
                    G_CALLBACK (on_add_clicked),
                    NULL);
  g_signal_connect ((gpointer) adi, "clicked",
                    G_CALLBACK (on_adi_clicked),
                    NULL);
  g_signal_connect ((gpointer) ana, "clicked",
                    G_CALLBACK (on_ana_clicked),
                    NULL);
  g_signal_connect ((gpointer) ani, "clicked",
                    G_CALLBACK (on_ani_clicked),
                    NULL);
  g_signal_connect ((gpointer) cma, "clicked",
                    G_CALLBACK (on_cma_clicked),
                    NULL);
  g_signal_connect ((gpointer) cmc, "clicked",
                    G_CALLBACK (on_cmc_clicked),
                    NULL);
  g_signal_connect ((gpointer) cmp, "clicked",
                    G_CALLBACK (on_cmp_clicked),
                    NULL);
  g_signal_connect ((gpointer) cpi, "clicked",
                    G_CALLBACK (on_cpi_clicked),
                    NULL);
  g_signal_connect ((gpointer) daa, "clicked",
                    G_CALLBACK (on_daa_clicked),
                    NULL);
  g_signal_connect ((gpointer) dad, "clicked",
                    G_CALLBACK (on_dad_clicked),
                    NULL);
  g_signal_connect ((gpointer) dcr, "clicked",
                    G_CALLBACK (on_dcr_clicked),
                    NULL);
  g_signal_connect ((gpointer) dcx, "clicked",
                    G_CALLBACK (on_dcx_clicked),
                    NULL);
  g_signal_connect ((gpointer) inr, "clicked",
                    G_CALLBACK (on_inr_clicked),
                    NULL);
  g_signal_connect ((gpointer) inx, "clicked",
                    G_CALLBACK (on_inx_clicked),
                    NULL);
  g_signal_connect ((gpointer) ora, "clicked",
                    G_CALLBACK (on_ora_clicked),
                    NULL);
  g_signal_connect ((gpointer) ori, "clicked",
                    G_CALLBACK (on_ori_clicked),
                    NULL);
  g_signal_connect ((gpointer) ral, "clicked",
                    G_CALLBACK (on_ral_clicked),
                    NULL);
  g_signal_connect ((gpointer) rar, "clicked",
                    G_CALLBACK (on_rar_clicked),
                    NULL);
  g_signal_connect ((gpointer) rlc, "clicked",
                    G_CALLBACK (on_rlc_clicked),
                    NULL);
  g_signal_connect ((gpointer) rrc, "clicked",
                    G_CALLBACK (on_rrc_clicked),
                    NULL);
  g_signal_connect ((gpointer) sbb, "clicked",
                    G_CALLBACK (on_sbb_clicked),
                    NULL);
  g_signal_connect ((gpointer) sbi, "clicked",
                    G_CALLBACK (on_sbi_clicked),
                    NULL);
  g_signal_connect ((gpointer) stc, "clicked",
                    G_CALLBACK (on_stc_clicked),
                    NULL);
  g_signal_connect ((gpointer) sub, "clicked",
                    G_CALLBACK (on_sub_clicked),
                    NULL);
  g_signal_connect ((gpointer) sui, "clicked",
                    G_CALLBACK (on_sui_clicked),
                    NULL);
  g_signal_connect ((gpointer) xra, "clicked",
                    G_CALLBACK (on_xra_clicked),
                    NULL);
  g_signal_connect ((gpointer) xri, "clicked",
                    G_CALLBACK (on_xri_clicked),
                    NULL);
  g_signal_connect ((gpointer) airthmetic, "clicked",
                    G_CALLBACK (on_airthmetic_clicked),
                    NULL);
  g_signal_connect ((gpointer) mov, "clicked",
                    G_CALLBACK (on_mov_clicked),
                    NULL);
  g_signal_connect ((gpointer) shld, "clicked",
                    G_CALLBACK (on_shld_clicked),
                    NULL);
  g_signal_connect ((gpointer) mvi, "clicked",
                    G_CALLBACK (on_mvi_clicked),
                    NULL);
  g_signal_connect ((gpointer) pchl, "clicked",
                    G_CALLBACK (on_pchl_clicked),
                    NULL);
  g_signal_connect ((gpointer) xchg, "clicked",
                    G_CALLBACK (on_xchg_clicked),
                    NULL);
  g_signal_connect ((gpointer) ldax, "clicked",
                    G_CALLBACK (on_ldax_clicked),
                    NULL);
  g_signal_connect ((gpointer) pop, "clicked",
                    G_CALLBACK (on_pop_clicked),
                    NULL);
  g_signal_connect ((gpointer) push, "clicked",
                    G_CALLBACK (on_push_clicked),
                    NULL);
  g_signal_connect ((gpointer) xthl, "clicked",
                    G_CALLBACK (on_xthl_clicked),
                    NULL);
  g_signal_connect ((gpointer) sta, "clicked",
                    G_CALLBACK (on_sta_clicked),
                    NULL);
  g_signal_connect ((gpointer) lda, "clicked",
                    G_CALLBACK (on_lda_clicked),
                    NULL);
  g_signal_connect ((gpointer) sphl, "clicked",
                    G_CALLBACK (on_sphl_clicked),
                    NULL);
  g_signal_connect ((gpointer) lhld, "clicked",
                    G_CALLBACK (on_lhld_clicked),
                    NULL);
  g_signal_connect ((gpointer) lxi, "clicked",
                    G_CALLBACK (on_lxi_clicked),
                    NULL);
  g_signal_connect ((gpointer) stax, "clicked",
                    G_CALLBACK (on_stax_clicked),
                    NULL);
  g_signal_connect ((gpointer) in, "clicked",
                    G_CALLBACK (on_in_clicked),
                    NULL);
  g_signal_connect ((gpointer) out, "clicked",
                    G_CALLBACK (on_out_clicked),
                    NULL);
  g_signal_connect ((gpointer) data_transfer, "clicked",
                    G_CALLBACK (on_data_transfer_clicked),
                    NULL);
  g_signal_connect ((gpointer) jmp, "clicked",
                    G_CALLBACK (on_jmp_clicked),
                    NULL);
  g_signal_connect ((gpointer) call, "clicked",
                    G_CALLBACK (on_call_clicked),
                    NULL);
  g_signal_connect ((gpointer) ret, "clicked",
                    G_CALLBACK (on_ret_clicked),
                    NULL);
  g_signal_connect ((gpointer) jx, "clicked",
                    G_CALLBACK (on_jx_clicked),
                    NULL);
  g_signal_connect ((gpointer) cx, "clicked",
                    G_CALLBACK (on_cx_clicked),
                    NULL);
  g_signal_connect ((gpointer) rx, "clicked",
                    G_CALLBACK (on_rx_clicked),
                    NULL);
  g_signal_connect ((gpointer) branch, "clicked",
                    G_CALLBACK (on_branch_clicked),
                    NULL);
  g_signal_connect ((gpointer) carry, "clicked",
                    G_CALLBACK (on_carry_clicked),
                    NULL);
  g_signal_connect ((gpointer) zero, "clicked",
                    G_CALLBACK (on_zero_clicked),
                    NULL);
  g_signal_connect ((gpointer) evan_piraty, "clicked",
                    G_CALLBACK (on_evan_piraty_clicked),
                    NULL);
  g_signal_connect ((gpointer) plus, "clicked",
                    G_CALLBACK (on_plus_clicked),
                    NULL);
  g_signal_connect ((gpointer) nocarry, "clicked",
                    G_CALLBACK (on_nocarry_clicked),
                    NULL);
  g_signal_connect ((gpointer) nozero, "clicked",
                    G_CALLBACK (on_nozero_clicked),
                    NULL);
  g_signal_connect ((gpointer) odd_piraty, "clicked",
                    G_CALLBACK (on_odd_piraty_clicked),
                    NULL);
  g_signal_connect ((gpointer) minus, "clicked",
                    G_CALLBACK (on_minus_clicked),
                    NULL);
  g_signal_connect ((gpointer) condition, "clicked",
                    G_CALLBACK (on_condition_clicked),
                    NULL);
  g_signal_connect ((gpointer) hlt, "clicked",
                    G_CALLBACK (on_hlt_clicked),
                    NULL);
  g_signal_connect ((gpointer) nop, "clicked",
                    G_CALLBACK (on_nop_clicked),
                    NULL);
  g_signal_connect ((gpointer) di, "clicked",
                    G_CALLBACK (on_di_clicked),
                    NULL);
  g_signal_connect ((gpointer) ei, "clicked",
                    G_CALLBACK (on_ei_clicked),
                    NULL);
  g_signal_connect ((gpointer) rim, "clicked",
                    G_CALLBACK (on_rim_clicked),
                    NULL);
  g_signal_connect ((gpointer) sim, "clicked",
                    G_CALLBACK (on_sim_clicked),
                    NULL);
  g_signal_connect ((gpointer) rst, "clicked",
                    G_CALLBACK (on_rst_clicked),
                    NULL);
  g_signal_connect ((gpointer) machine_control, "clicked",
                    G_CALLBACK (on_machine_control_clicked),
                    NULL);
	
	/*Some hack from the glade code to make certain things global*/
  dt_table=data_transfer_table;
  al_table=table3;
  mc_table=table8;
  br_table=table6;
  con_table=table7;
  hex_table=table4;
  
  /*initilise keypad*/
  gsim_init_keypad_state();

  return keypad;
}
